import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

public class TEST {
    public static void Hanoi(int n ,char curr,char tran,char dest){
        if (n == 1) {
            System.out.println(curr + "->" + dest);
        }else {
            Hanoi(n-1,curr,dest,tran);
            System.out.println(curr + "->" + dest);
            Hanoi(n-1,tran,curr,dest);
        }}
    public static void main1(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入层数：");
        int n = sc.nextInt();
        Hanoi(n,'A','B','C');
    }

    public static void main2(String[] args) {
        int[] array1 = new int[]{1,2,3,4,5,6,7,8,9,0};
        System.out.println(array1[0]);
        System.out.println(array1[1]);
        System.out.println(array1[2]);
        System.out.println(array1[3]);
        System.out.println(array1.length);
        int i = 0;
        for(i = 0;i<array1.length;i++){
            System.out.print("nihao!" + " ");
        }
        for(int x:array1
            ){
            System.out.println(x);
        }
    }

    public static void func() {
        int[] array1 = new int[3];
        array1[0] = 10;
        array1[1] = 20;
        array1[2] = 30;
        int[] array2 = new int[]{1,2,3,4,5};
        array2[0] = 100;
        array2[1] = 200;
        array1 = array2;
        array1[2] = 300;
        array1[3] = 400;
        array2[4] = 500;
        for (int i = 0; i < array2.length; i++) {
            System.out.println(array2[i]);
        }
    }

    public static void main4(String[] args) {
        int[] array1 = new int[]{1,2,3,4,5,6};
        String newArr = Arrays.toString(array1);
        System.out.println(newArr);
    }

    public static void main5(String[] args) {
        int[] arr = {1,2,3,4,5,6};
        int[] newArr = arr;
        newArr[1] = 100;
        System.out.println(Arrays.toString(arr));
        arr[1] = 2;
        newArr = Arrays.copyOf(arr,arr.length);
        arr[1] = 100;
        System.out.println(Arrays.toString(newArr));
        int[] newArr2 = Arrays.copyOfRange(arr,2,4);
        System.out.println(Arrays.toString(newArr2));
    }

    public static void main6(String[] args) {
        int[] arr = new int[100];
        int i = 0;
        for(i = 0;i < arr.length;i++){
            arr[i] = i + 1;
        }
        System.out.println(Arrays.toString(arr));
    }

    public static int[] transform(int[] array){
        int i = 0;
        for (i = 0;i < array.length;i++){
            array[i] = array[i] * 2;
        }
        return array;
    }

    public static void main7(String[] args) {
        int[] arr = {1,2,3,4,5,6,7,8,8};
        System.out.println(Arrays.toString(arr));
        transform(arr);
        System.out.println(Arrays.toString(arr));
    }

    //数组求和
    public static int sum(int[] array){
        int add = 0,i = 0;
        for (i = 0;i < array.length;i++){
            add += array[i];
        }
        return add;
    }

    public static void main8(String[] args) {
        int[] arr = {5,5,5,5,5,5};//六个五，30
        int sum = 0;
        sum = sum(arr);
        System.out.println(sum);

    }

    //奇数位于偶数前
    public static void adjust(int[] arr){
        int i = 0,j = arr.length-1;
        while(i < j){
            if(arr[i] % 2 == 0 && arr[j] % 2 != 0){
                int tmp = 0;
                tmp = arr[i];
                arr[i] = arr[j];
                arr[j] = tmp;
            }
            i++;
            j--;
        }
    }

    public static void main9(String[] args) {
        int[] arr = {1,2,3,4,5,6};
        System.out.println(Arrays.toString(arr));
        adjust(arr);
        System.out.println(Arrays.toString(arr));
    }

    //两数之和
    public static int[] search(int[] arr,int target){
        int i = 0,j = 0;
        int[] arr1 = new int[2];
        for (i = 0;i < arr.length-1;i++){
            for (j = arr.length-1;j >i;j--){
                if (arr[i] + arr[j] == target){
                    arr1[0] = i;
                    arr1[1] = j;

                }
            }
        }
        return arr1;
    }

    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7,8};
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入数字：");
        int target = sc.nextInt();
        int[] ret = search(arr,target);
        System.out.println(Arrays.toString(ret));
    }
}
